//
//  HealthView.m
//  SHHCPhone
//
//  Created by gfsh on 14-6-23.
//  Copyright (c) 2014年 sheng long. All rights reserved.
//

#import "HealthView.h"
#import "HealthCell.h"

@implementation HealthView
{
    NSArray *data;
}

- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
    self = [super initWithFrame:frame style:style];
    if (self) {
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.backgroundColor = [UIColor clearColor];
        self.backgroundView = nil;
        self.dataSource = self;
        self.delegate = self;
    }
    return self;
}

- (void)loadData:(NSArray*)cells
{
    data = cells;
    [self reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return data.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *identifier = @"healthIdentifier";
    HealthCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[HealthCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.bg.frame = CGRectMake(10, 10, self.frame.size.width-20, 180-10);
        cell.bg.layer.borderWidth = 1.f;
        cell.bg.layer.borderColor = [UIColor lightGrayColor].CGColor;
        cell.topicIV.frame = CGRectMake(0, 0, cell.bg.frame.size.width, cell.bg.frame.size.height-40);
        cell.topicIV.backgroundColor = [UIColor lightGrayColor];
        cell.topicLab.frame = CGRectMake(5, cell.topicIV.frame.origin.y+cell.topicIV.frame.size.height, cell.bg.frame.size.width, 20);
        cell.timeLab.frame = CGRectMake(5, cell.topicLab.frame.origin.y+cell.topicLab.frame.size.height, cell.topicLab.frame.size.width, 20);
    }

    cell.topicLab.text = [data[indexPath.row] objectForKey:@"topic"];
    cell.timeLab.text = [data[indexPath.row] objectForKey:@"time"];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 180.f;
}

@end
